﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WmsProductInStockView.aspx.cs" Inherits="JYH.Web.MES.WMS.UI.WmsProductInStockView" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script type="text/javascript">

        let res = {};
        async function Translation() {
            if (res != null) {
                if (res.PageTitile != null) {
                    document.title = res.PageTitile;
                    

                    $('#BtnSave').linkbutton({
                        text: res.BtnSave
                    });
                    $('#BtnSearch').linkbutton({
                        text: res.BtnSearch
                    });
                   
                    $('#BtnInport').linkbutton({
                        text: res.BtnInport
                    });
                    $('#tCreateTime').textbox({
                   
                        label: res.ReciveDate

                    });
                    
                    $('#tReciveOrderNO').textbox({
                        prompt: res.ReciveOrderNO,
                        label: res.ReciveOrderNO

                    });
                    $('#tPatnerOrderNO').textbox({
                        prompt: res.PartnerOrderNO,
                        label: res.PartnerOrderNO
                        //lable: res.ReciveOrderNO
                    });
                    $('#tPartnerNO').textbox({
                        prompt: res.DBClick+ ' '+ res.VendorNO,
                        label: res.VendorNO
                    });
                    $('#tPartnerName').textbox({
                         
                        label: res.VendorName
                    });
                    $('#txtProduct').textbox({
                        prompt: res.MaterialNO + '/' + res.MaterialName
                        //lable: res.ReciveOrderNO
                    });
                    $('#ItemDate').datagrid('options').columns[0][1].title = res.ERPItem;
                    $('#ItemDate').datagrid('options').columns[0][2].title = res.MaterialNO;
                    $('#ItemDate').datagrid('options').columns[0][3].title = res.MaterialName;
                    $('#ItemDate').datagrid('options').columns[0][4].title = res.MaterialDesc;
                    $('#ItemDate').datagrid('options').columns[0][5].title = res.BatchNO;
                    $('#ItemDate').datagrid('options').columns[0][6].title = res.ReciveQty;
                    $('#ItemDate').datagrid('options').title = res.RCOrderList;
                    $('#ItemDate').datagrid('resize');
                    $('#ItemDate').datagrid(); // 重新初始化

                    $('#ttsd').datagrid('options').columns[0][0].title = res.VendorNO;
                    $('#ttsd').datagrid('options').columns[0][1].title = res.VendorName;
                    $('#ttsd').datagrid('options').columns[0][2].title = res.VendorCode;
                    $('#ttsd').datagrid('resize');
                    $('#ttsd').datagrid(); // 重新初始化
                    // $('#tt').datagrid('load'); // 加载数据
                }
            }
        }
        async function TranslationPage() {

            try {
                var lang = {
                    PageName: 'ReciveOrder',
                    LanguageNO: navigator.language
                };

                var url = "/api/SYS/GetPageLanguage";

                // var element = document.getElementById("Literal1");

                let c = await $.ajax({
                    url: url, // 替换为你的API或服务器端点
                    type: 'POST', // 或者 'POST'，取决于你的请求类型
                    data: lang,
                    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                    success: function (data) {
                        console.log(JSON.stringify(data));
                        // 假设你需要在请求成功后显示元素
                        if (data.Code == 200) {

                            res = data.Items[0];
                            console.log(JSON.stringify(res));
                            if (res != null) {


                                Translation();



                                // document.querySelector('input[type="qBarcodeNO"]').setAttribute('data-options', 'Input Barcode NO');;

                            }
                        }
                        if (data.Code == 500) {

                            console.log(JSON.stringify(data));
                            Notice(data.Message);

                        }

                    },
                    error: function (xhr, status, error) {
                        // 错误处理
                    }
                });



            } catch (error) { }
            //  console.error('Request error:', error);

        };

        $(document).ready(function () {
            TranslationPage();
        }
        );


        function LoadItem(rows) {
            $("#hReciveOrderID").val(rows.ReciveOrderID);
            $("#hWarehouseName").val(rows.WarehouseName);
            $('#tReciveOrderNO').textbox('setValue', rows.ReciveOrderNO);
            $('#tCreateTime').textbox('setValue', rows.CreateTime);
            $('#tPartnerNO').textbox('setValue', rows.PartnerNO);
            $('#tPatnerOrderNO').textbox('setValue', rows.PatnerOrderNO);
            $('#tPartnerName').textbox('setValue', rows.PartnerName);
        }
        $(function () {
            // 使用window.location.href获取当前URL
            const url = new URL(window.location.href);
            // 使用URLSearchParams接口获取URL参数
            const params = new URLSearchParams(url.search);
            const pa = JSON.parse(decodeURIComponent(params.get('params')));
            // 初始化
            if (pa != null) {
                LoadItem(pa);
                const view = params.get('view');
                if (view == "view") {
                    /* $("#A1").style.display= "none";*/
                    $('#SaveItems').hide();
                    $('#AddItem').hide();
                }
            } else {
                $('#tb').find('input.easyui-textbox').textbox('setValue', '');
            }

            //收料明细
            $('#ItemDate').datagrid({
                pageSize: 20,
                loadMsg: "正在接收数据...",
                method: 'Get',
                iconCls: 'icon-reload',
                url: '/api/WMS/QueryReciveOrderItem',
                queryParams: {
                    ReciveOrderID: $("#hReciveOrderID").val(),
                    MaterialNO: "",
                    sort: "",
                    order: ""
                },
                height: window.innerHeight - 150,
                idField: 'ReciveItemID',
                striped: true,      //隔行变色
                singleSelect: true, //是否单选
                pagination: true,   //分页控件  
                scrollbarSize: 0,
                fitColumns: true,
                columns: [[
                    {
                        field: 'ReciveItemID', // 复选框字段
                        checkbox: true // 表示这是一个复选框列
                    },
                    { field: 'ERPItem', title: 'ERP项次', width: 80, sortable: true },
                    { field: 'MaterialNO', title: '物料编号', width: 100, sortable: true },
                    { field: 'MaterialName', title: '物料名称' },
                    { field: 'MaterialDesc', title: '物料规格' },
                    { field: 'BatchNO', title: '物料批号', width: 150 },
                    { field: 'ReciveQty', title: '收料数量', width: 70  }
         

                ]],
                loadFilter: function (data) {
                    return JSON.parse(data);
                },
                toolbar: "#toolbar",
                rownumbers: true,   //行号 
                onLoadSuccess: function (data) {
                    $('#ItemDate').datagrid("fillRows");
                    $('#ItemDate').datagrid('resize');
                },
                onSortColumn: function (sort, order) {
                    $("#hSort").val(order);
                    $("#hOrder").val(sort);
                }
            });
            DateOK();

            //供应商
            $('#PartnerDialog').dialog({
                title: '供应商列表',
                width: 800,
                height: 480,
                closed: true, // 设置为 true 以初始化时隐藏对话框
                modal: true,
                onClose: function () {
                    // 对话框关闭时触发的事件

                }
            });
            //双击事件
            $('#tPT').dblclick(function () {
                $('#PartnerDialog').dialog('open');
                DateOK();
            });
            $(window).resize(function () {
                $('#ItemDate').datagrid('resize');

            });
        })

        function DateOK() {
            //BasPartnerInfo
            $('#ttsd').datagrid({
                loadMsg: "正在接收数据...",
                iconCls: 'icon-reload',
                url: '',
                idField: 'PartnerID',
                autoRowHeight: false,
                fitColumns: false,
                scrollbarSize: 0,
                height: document.documentElement.clientHeight - 250,
                pageSize: 20,
                sortable: true,
                striped: true,      //隔行变色
                singleSelect: true, //是否单选
                pagination: true,   //分页控件  
                rownumbers: true,
                columns: [[
                    {
                        field: 'PartnerID', // 复选框字段
                        checkbox: true // 表示这是一个复选框列
                    },
                    { field: 'PartnerNO', title: '伙伴编号' },
                    { field: 'PartnerName', title: '伙伴名称' },
                    { field: 'PartnerCode', title: '伙伴代码' }

                ]],
                onDblClickRow: function (index, row) {
                    if (row == null) {
                        Alert("请选择一行数据");
                        return false;
                    }
                    $('#hPartnerID').val(row.PartnerID);
                    $("#tPartnerNO").textbox('setValue', row.PartnerNO);
                    $("#tPartnerName").textbox('setValue', row.PartnerName);
                    $('#PartnerDialog').dialog('close');
                },
                loadFilter: function (data) {
                    if (data.d) {
                        return data.d;
                    } else {
                        return JSON.parse(data);
                    }

                }

            });
            $(window).resize(function () {
                $('#ttsd').datagrid('resize');
            });
        }

        //TPartnerLocal 查询
        function TPartnerLocal() {
            var PartnerNO = $("#DPartnerNO").val();//编号
            var PartnerName = $("#DPartnerName").val();//名称
            $("#ttsd").datagrid({
                url: '/api/BAS/QueryPartner',
                method: 'Get',
                queryParams: {
                    PartnerNO: PartnerNO,
                    PartnerName: PartnerName,
                    order: '',
                    sort: ''
                },
                loadFilter: function (data) {
                    if (data.d) {
                        return data.d;
                    } else {
                        return JSON.parse(data);
                    }

                }
            });
        }

        function myformatter(date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d);
        }
        function myparser(s) {
            if (!s) return new Date();
            var ss = (s.split('-'));
            var y = parseInt(ss[0], 10);
            var m = parseInt(ss[1], 10);
            var d = parseInt(ss[2], 10);
            if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
                return new Date(y, m - 1, d);
            } else {
                return new Date();
            }
        }
        //新增保存
        function ItemSave() {
            if (!validateForm()) {
                return;
            }
            var url = "/api/WMS/SaveWmsReciveOrderInfo";
            const ReciveOrderNO = $("#tReciveOrderNO").val();
            var datalist = {
                ReciveOrderID: $("#hReciveOrderID").val(),
                ReciveOrderNO: ReciveOrderNO,
                ReciveDate: $("#tCreateTime").val(),
                PartnerID: $("#hPartnerID").val(),
                PatnerOrderNO: $("#tPatnerOrderNO").val()
            }
            DataService.PostJson(url, datalist, (err, res) => {
                if (err) {
                    Notice("操作成功");
                    console.log(res);
                    $("#hReciveOrderID").val(res.Items[0].ReciveOrderID);
                    if (!ReciveOrderNO) {
                        $("#tReciveOrderNO").textbox("setValue",res.Items[0].ReciveOrderNO);
                    }
                    SInItem();
                } else {
                    Alert("操作失败" + res);
                }
            })
        }

        //收料明细检索
        function SInItem() {
            var ReciveOrderID = $("#hReciveOrderID").val();
            var MaterialNO = $('#txtProduct').val();
            var sort = $("#hSort").val();
            var order = $("#hOrder").val();
            //排序字段
            $("#ItemDate").datagrid({
                method: 'Get',
                url: '/api/WMS/QueryReciveOrderItem',
                queryParams: {
                    ReciveOrderID: ReciveOrderID,
                    MaterialNO: MaterialNO,
                    sort: sort,
                    order: order
                },
                loadFilter: function (data) {
                    return JSON.parse(data);
                }
            });
            $('#ItemDate').datagrid('unselectAll', 'true');
        }

        //根据状态改变值color
        function setColumnForeColor(value, row, index) {
            /// 记录状态 0 编辑 1 审核 2 待入库 3 完成  4 回抛 9 作废
            if (value === '审核') {
                //橘色
                return '<span style="color:#ff9900;">' + value + '</span>';
            }
            if (value == '编辑') {
                //红色
                return '<span style="color:red;">' + value + '</span>';
            }
            if (value == '待入库') {
                //黄色
                return '<span style="color:#ffff00;">' + value + '</span>';
            }
            if (value == '完成') {
                //绿色
                return '<span style="color:#00ff00;">' + value + '</span>';
            }
            if (value == '作废') {
                //灰色
                return '<span style="color:#666666;">' + value + '</span>';
            }
            return value;
        }

        //导入
        function ExeclTo() {

            OpenSubWindow("收料明细信息导入", "WMS/UI/BasReciveItemEdit.aspx?params=" + $("#hReciveOrderID").val(), 500, 280, function () {
                SInItem();
            });
        }
    </script>
</head>
<body>
    <form runat="server" id="ff">
        <%--排序隐藏值--%>
        <asp:HiddenField runat="server" ID="hSort" />
        <asp:HiddenField runat="server" ID="hOrder" />
        <asp:HiddenField runat="server" ID="hReciveOrderID" />
        <asp:HiddenField runat="server" ID="hPartnerID" />
        <div class="pagebox">
            <div class="cbox">
                <!--工具栏-->
                <div class="easyui-panel" style="padding: 15px; width: 100%;">
                    <div id="tb">
                        <ul class="flist">
                            <li>
                                <input class="easyui-textbox" type="text" id="tReciveOrderNO" runat="server" data-options="prompt:'保存自动生成',label:'收料单号:'" style="width: 250px; height: 35px; line-height: 35px;" />
                            </li>
                            <li>
                                <input class="easyui-datebox" id="tCreateTime" value="1" data-options="prompt:'制单日期',label:'制单日期:',formatter:myformatter,parser:myparser" style="width: 250px; height: 35px;" required />
                            </li>
                        </ul>
                        <ul class="flist">
                            <li>
                                <input class="easyui-textbox" type="text" id="tPatnerOrderNO" runat="server" data-options="label:'送货单号:'" style="width: 250px; height: 35px; line-height: 35px;" />
                            </li>
                            <li id="tPT">
                                <input class="easyui-textbox" type="text" id="tPartnerNO" runat="server" data-options="prompt:'双击获取供应商',label:'供应商信息:'" style="width: 250px; height: 35px; line-height: 35px;" required />
                            </li>
                            <li>
                                <input class="easyui-textbox" type="text" id="tPartnerName" runat="server" data-options="label:'供应商名称:'" style="width: 330px; height: 35px; line-height: 35px;" readonly />
                            </li>
                            <a href="javascript:;" class="easyui-linkbutton c1" onclick="ItemSave()" id="BtnSave" style="margin-left: 30px">保存主档</a>
                        </ul>
                    </div>

                </div>
            </div>
            <div class="cbox">
                <div title="收料明细">
                    <table id="ItemDate"></table>
                </div>
            </div>

        </div>



    </form>
    <div id="toolbar" style="padding: 5px; height: auto">
        <div style="margin-bottom: 5px;">
            <ul class="flist">
                <li>
                    <input class="easyui-textbox" type="text" id="txtProduct" data-options="prompt:'物料名称/编号'" style="width: 250px; height: 35px; line-height: 35px;" />
                </li>
                <a href="#" class="easyui-linkbutton" iconcls="icon-edit" plain="true" runat="server" id="BtnSearch" onclick="SInItem()">检索</a>
                <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" runat="server" id="BtnInport" onclick="ExeclTo()">导入</a>
            </ul>
        </div>
    </div>

    <%--    合作伙伴dialog--%>
    <div id="PartnerDialog" class="easyui-dialog" title="供应商列表" style="width: 700px; height: 560px; padding: 5px" data-options="closed:true,modal:true">
        <div class="cbox">
            <ul class="flist">
                <li>
                    <input class="easyui-textbox" type="text" id="DPartnerNO" data-options="prompt:'请输入供应商编号'" style="width: 150px; height: 35px; line-height: 35px;" /></li>
                <li>
                    <input class="easyui-textbox" type="text" id="DPartnerName" data-options="prompt:'请输入供应商名称'" style="width: 150px; height: 35px; line-height: 35px;" /></li>
                <a href="javascript:void(0)" class="easyui-linkbutton c1" onclick="TPartnerLocal()" id="BtnSearch01" data-options="iconCls:'icon-sousuo',selected:true">查询</a>
            </ul>
        </div>
        <div class="cbox">
            <!--查询结果清单-->
            <table id="ttsd">
            </table>
        </div>
    </div>
</body>
</html>
